package com.more.offer.algorithm.sort.sort_04;

/**
 * Date: 2020-03-15 23:32
 * Author: pinoc
 * Desc: 插入排序 第二位开始
 */
public class InsertSort {
	public static void insertionSort(int[] array) {
		for (int i = 1; i < array.length; i++) {
			for (int j = i; j > 0; j--) {
				if (array[j] < array[j - 1]) {
					int temp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = temp;
				} else {
					break;
				}
			}
		}
	}
	public static void main(String[] args) {
		int[] array = {8,5,2,6,1,10,50,0,7,9,12,60,22,3};
		insertionSort(array);
		for (int i : array) {
			System.out.print(i+" ");
		}
	}
}
